/*
 * Copyright 2010 Kevin L'Huillier <klhuillier@gmail.com>
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package org.lhuillier.pwsafe.model;


/**
 * A database-wide password policy.
 * <p>
 * This policy type should only be gotten from a {@link Database} instance.
 * Its values are backed by the Database's {@link Preferences} instance. Any
 * changes to this policy will be reflected in the underlying Preferences and
 * vice-versa.
 */
public class DbPwPolicy implements PwPolicy {
    private final Preferences prefs;
    
    DbPwPolicy(Preferences prefs) {
        this.prefs = prefs;
    }

    @Override
    public boolean getUseLowercase() {
        return prefs.getBoolean(BooleanPrefType.PW_USE_LOWERCASE);
    }

    @Override
    public void setUseLowercase(boolean value) {
        prefs.setBoolean(BooleanPrefType.PW_USE_LOWERCASE, value);
    }

    @Override
    public boolean getUseUppercase() {
        return prefs.getBoolean(BooleanPrefType.PW_USE_UPPERCASE);
    }

    @Override
    public void setUseUppercase(boolean value) {
        prefs.setBoolean(BooleanPrefType.PW_USE_UPPERCASE, value);
    }

    @Override
    public boolean getUseDigits() {
        return prefs.getBoolean(BooleanPrefType.PW_USE_DIGITS);
    }

    @Override
    public void setUseDigits(boolean value) {
        prefs.setBoolean(BooleanPrefType.PW_USE_DIGITS, value);
    }

    @Override
    public boolean getUseSymbols() {
        return prefs.getBoolean(BooleanPrefType.PW_USE_SYMBOLS);
    }

    @Override
    public void setUseSymbols(boolean value) {
        prefs.setBoolean(BooleanPrefType.PW_USE_SYMBOLS, value);
    }

    @Override
    public boolean getUseHexDigits() {
        return prefs.getBoolean(BooleanPrefType.PW_USE_HEX_DIGITS);
    }

    @Override
    public void setUseHexDigits(boolean value) {
        prefs.setBoolean(BooleanPrefType.PW_USE_HEX_DIGITS, value);
    }

    @Override
    public boolean getUseEasyVision() {
        return prefs.getBoolean(BooleanPrefType.PW_USE_EASY_VISION);
    }

    @Override
    public void setUseEasyVision(boolean value) {
        prefs.setBoolean(BooleanPrefType.PW_USE_EASY_VISION, value);
    }

    @Override
    public boolean getMakePronounceable() {
        return prefs.getBoolean(BooleanPrefType.PW_MAKE_PRONOUNCEABLE);
    }

    @Override
    public void setMakePronounceable(boolean value) {
        prefs.setBoolean(BooleanPrefType.PW_MAKE_PRONOUNCEABLE, value);
    }

    @Override
    public int getTotalLength() {
        return prefs.getInteger(IntegerPrefType.PW_DEFAULT_LENGTH);
    }

    @Override
    public void setTotalLength(int value) {
        prefs.setInteger(IntegerPrefType.PW_DEFAULT_LENGTH, value);
    }

    @Override
    public int getMinLowerLetters() {
        return prefs.getInteger(IntegerPrefType.PW_LOWERCASE_MIN_LENGTH);
    }

    @Override
    public void setMinLowerLetters(int value) {
        prefs.setInteger(IntegerPrefType.PW_LOWERCASE_MIN_LENGTH, value);
    }

    @Override
    public int getMinUpperLetters() {
        return prefs.getInteger(IntegerPrefType.PW_UPPERCASE_MIN_LENGTH);
    }

    @Override
    public void setMinUpperLetters(int value) {
        prefs.setInteger(IntegerPrefType.PW_UPPERCASE_MIN_LENGTH, value);
    }

    @Override
    public int getMinDigits() {
        return prefs.getInteger(IntegerPrefType.PW_DIGIT_MIN_LENGTH);
    }

    @Override
    public void setMinDigits(int value) {
        prefs.setInteger(IntegerPrefType.PW_DIGIT_MIN_LENGTH, value);
    }

    @Override
    public int getMinSymbols() {
        return prefs.getInteger(IntegerPrefType.PW_SYMBOL_MIN_LENGTH);
    }

    @Override
    public void setMinSymbols(int value) {
        prefs.setInteger(IntegerPrefType.PW_SYMBOL_MIN_LENGTH, value);
    }
    
}
